<?php 
	echo $this->inlineScript()->setScript('$(document).ready(function(){
		$("#from").datepicker({ dateFormat: "yy-mm-dd" });
		$("#to").datepicker({ dateFormat: "yy-mm-dd" });
	})');
?>
<form id="formrap" method="post" action="">
<input type="hidden" id="excel" name="excel" value="0" />
	<table cellspacing="1" cellpadding="6" class="tlist">
		<tr>
			<td>
				Od: <?php echo $this->formText( 'from', $this->from ); ?>
			</td>
			<td>
				Do: <?php echo $this->formText( 'to', $this->to ); ?>
			</td>
			<td>
				<a onclick="$('#formrap').find('#excel').val( 0 );$('#formrap').submit()" class="button" href="javascript::void(null)">
					<div style="background:url(<?php echo $this->baseUrl() ?>/public/images/plus_16.png);" class="inb">Generuj raport na ekran</div>
				</a>
			</td>
			<td>
				<a onclick="$('#formrap').find('#excel').val( 1 );$('#formrap').submit()" class="button" href="javascript::void(null)">
					<div style="background:url(<?php echo $this->baseUrl() ?>/public/images/gear_16.png);" class="inb">Generuj raport do Excel</div>
				</a>
			</td>
		</tr>
	</table>
</form>

<div class="bglist">
	<div class="bglistq">
		<table cellspacing="1" cellpadding="6" class="tlist">
			<tr>
				<th>Id</th>
				<th>Nazwa</th>
				<th>Ilość</th>
			</tr>
			<?php 
			$arr = array();
			foreach( $this->list as $item ){

				if( !isSet( $arr[$item['p_id']] ) ) {
					$arr[$item['p_id']]['item'] = $item;
					$arr[$item['p_id']]['cnt'] = 1;
				} else {
					$arr[$item['p_id']]['cnt'] = $arr[$item['p_id']]['cnt'] + 1;					
				}
				
			}
			
			foreach( $arr as $item ) { 
				
			?>
			<tr>
				<td><?php echo $item['item']['p_id'] ?></td>
				<td><?php echo $item['item']['name_pl'] ?></td>
				<td><?php echo $item['cnt'] ?></td>
			</tr>
			<?php } ?>
		</table>
	</div>
</div>